rm(list=ls())

# DATA
data_anova<-data.frame(read.csv("IOdata.csv"))


#################ANALYSIS##############

##IN THIS STACKED DATASET
##the variable "name" refers to the name of the organization in question.
##it takes two values: 0=national 1=international 

##the variable "total" refers to the index DV which takes the average of the values in the index questions for trust.
##the index variables are based on the variables called "trust, admire, american, spend" which codes the answers 
# to the relevant survey questions. 
##the variable "overall" refers to the questions for partisan perception.(1=Strongly liberal to 5= Strongly conservative.)
######################################
#active=participation in groups (1="never belonged, 4="active")
#ideology= (0=Conservative, 1=Liberal, 2=Moderate, 3=NoPref, NA=other or missing)
#party= (0=Republican, 1=Democrat, 2=Independent)
#order= control for the order effect. 

#### ANALYSIS####
#Define variables "id, name, order, party and ideology" as factors
data_anova$id<-as.factor(data_anova$id)
data_anova$name<-as.factor(data_anova$name)
data_anova$order<-as.factor(data_anova$order)
data_anova$party<-as.factor(data_anova$party)
data_anova$ideology<-as.factor(data_anova$ideology)


#############################
###### ANOVA   ##############
#############################

#Appendix Table H1: Trust in Organizations Index by International/National Treatment and Party
#####Analysis with party
# DV: total trust (the trust index)
summary(anova_res1 <- aov(total ~ name*party + active + order+ Error(id/name), data=data_anova[data_anova$party %in% c(0,1),]))

#Appendix Table H2: Trust in Organizations Index by International/National Treatment and Party 
#Without Participation in Organizations Covariat 
# DV: total trust (the trust index) (without active included)
summary(anova_res2 <- aov(total ~ name*party  + order+ Error(id/name), data=data_anova[data_anova$party %in% c(0,1),]))

#Appendix Table H3: Partisan Perceptions of Organization by International/National Treatment and Party
# DV: total trust (the index) (without active included)

summary(anova_res3<-aov(overall ~ name*party + Error(id/name), data=data_anova[data_anova$party %in% c(0,1),]))

#Appendix Table H4: Ideological Perceptions of Organizations by International/National Treatment and Ideology
#with ideology since this question asks about ideological tendency of the organization
summary(anove_res4<-(aov(overall ~ name*ideology + Error(id/name), data=data_anova[data_anova$ideology %in% c(0,1),])))



##########chronback's alpha #####################
psych::alpha(data_anova[data_anova$party %in% c(0,1), c(4,5,6,7)],check.keys=T)
psych::alpha(data_anova[data_anova$party %in% c(0,1), c(4,5,6,7)],check.keys=T)$total$std.alpha
cronbach(data_anova[c(4,5,6,7)])


